package com.mobiletrain.org.motherkitch;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

public class NetReceiver extends BroadcastReceiver {
    public NetReceiver() {
    }

    @Override
    public void onReceive(final Context context, Intent intent) {

        ConnectivityManager conn = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo net = conn.getActiveNetworkInfo();
        if(net!=null&&net.isAvailable()){
            int type = net.getType();
            switch(type){
                case ConnectivityManager.TYPE_WIFI:
                    Toast.makeText(context,"wifi连接",Toast.LENGTH_SHORT).show();
                    break;
                case ConnectivityManager.TYPE_MOBILE:
                    Toast.makeText(context,"手机网络连接",Toast.LENGTH_SHORT).show();
                    break;

            }
        }else{
            Toast.makeText(context,"网络连接错误",Toast.LENGTH_SHORT).show();
        }


    }

}
